//引入axios实例
import request from "@/utils/request"


//请求三级列表返回值的每一项
export interface reqCategoryItem {
    id: number,
    name: string,
    category1Id?: string
    category2Id?: string
}
//请求三级列表返回值的完整类型
export type reqCategoryList = reqCategoryItem[]
//1.请求一级列表
export const requestgetCategory1 = () => {
    return request.get<any, reqCategoryList>(`/admin/product/getCategory1`)
}

//2.请求二级列表
export const requestgetCategory2 = (category1Id: number) => {
    return request.get<any, reqCategoryList>(`/admin/product/getCategory2/${category1Id}`)
}

//3.请求三级列表
export const requestgetCategory3 = (category2Id: number) => {
    return request.get<any, reqCategoryList>(`/admin/product/getCategory3/${category2Id}`)
}




//商品属性列表请求返回值每一项中数组的类型
export interface reqAttrValueType {
    id?: number,
    valueName: string,
    attrId: number,
    isEdit? : boolean
}
//商品属性列表请求返回值每一项的类型
export interface reqAttrItemType {
    id?: number,
    attrName: string,
    categoryId: number,
    categoryLevel: number,
    attrValueList: reqAttrValueType[]
}

//商品属性列表请求的返回值类型
export type reqAttrListType = reqAttrItemType[]
//4.请求商品属性列表
export const requestgetattrList = (
    category1Id: number,
    category2Id: number,
    category3Id: number,
) => {
    return request.get<any, reqAttrListType>(`/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)
}

//5删除某个属性
export const requestDeleteAttr = (attrId: number) => {
    return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`);
  };
  
//6.新增或修改属性
export const requestUpdateOrAddAttr = (newAttr: reqAttrItemType) => {
    return request.post<any, null>(`/admin/product/saveAttrInfo`, newAttr);
};

